<!DOCTYPE html>
<html>
<head>
	<title>后台</title>
	<link rel="stylesheet" type="text/css" href="/bower_components\bootstrap\dist\css\bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="/style/article.css">
	<script type="text/javascript" src = '//cdn.bootcss.com/jquery/1.12.4/jquery.min.js'></script>
	<script type="text/javascript" src='/bower_components\bootstrap\dist\js\bootstrap.min.js'></script>
	<script type="text/javascript" src='/bower_components\bootstrap\dist\js\bootstrap.min.js'></script><script type="text/javascript" src = '/bower_components\upload-jquery\jquery.upload.js'></script>
	<script type="text/javascript" src='/bower_components\kindeditor\kindeditor-min.js'></script>
	<script type="text/javascript" src='/bower_components\kindeditor\lang\zh-CN.js'></script>
</head>
<body>
	<div class="container">
		<div class="row">
			<div class="col-md-offset-2 col-md-8">
				<div class="page-header">
					添加文章<a href="/addmin" class="btn btn-xs btn-info pull-right">查看列表</a>
				</div>
				<% if(error!=""){%>
					<div  class="alert alert-danger" role="alert">
						<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
					<%= error%></div>
				<%}%>
				<form action="" ="/addArticle" method="POST">
					<div class="form-group">
						<label for="exampleInputEmail1">文章标题</label>
						<div class="row">
							<div class="col-md-10">
						<input id="title" type="text" class="form-control" name="title" placeholder="请输入文章标题(必填)">
							</div>
							<div class="col-md-2">
								<span class="glyphicon glyphicon-asterisk asterisk" aria-hidden="true"></span>
							</div>
						</div>
					</div>
					<div class="form-group">
						<label for="exampleInputPassword1">图片</label><br/>
								<img id="img_preview" src=""  name="img" class="img-thumbnail" alt="请输入图片">
						<div class="row">
							<div class="col-md-8">
								<input id="image" class="form-control hidden" name="img">
								<input type="button" class="btn btn-primary" onclick="doUpload()" value="点击上传">
							</div>
							<div class="col-md-4">
							</div>
						</div>
					</div>
					<div class="form-group">
						<label for="exampleInputPassword1">文章内容</label>
						<textarea class="form-control" name="content" placeholder="请输入文章内容"></textarea>
					</div>
					<div class="form-group">
						<select class="form-control"  name="cata_id">
							<option class="form-control">---请输入分类---</option>
						<% for(var i = 0; i<catalogs.length; i++){%>
							<option value="<%= catalogs[i].id%>" class="form-control">
							<%= catalogs[i].name%></option>
						<%}%>
						</select>
					</div>
					<div class="form-group">
						<button id="submit" type="submit" class="btn btn-success">提交</button>
					</div>
				</form>
			</div>
		</div>
	</div>
</body>
</html>
<script type="">
		var editor;
	KindEditor.ready(function(K) {
		editor = K.create('textarea[name="content"]', {
			allowFileManager : true
		})
	});
	setTimeout(function(){
		$(".alert").fadeOut("close")
	},2000)
	/*
	$("#submit").click(function(){
		if($("#title").val() == ""){
			alert("标题不能为空")
			return false
		}
	})*/
	function doUpload(){
		$.upload({
			// 上传地址
			url: '/addmin/uploadFile', 
			// 文件域名字
			fileName: 'fileInput', 
			// 其他表单数据
			params: {},
			// 上传完成后, 返回json, text
			dataType: 'text',
			// 上传之前回调,return true表示可继续上传
			onSend: function() {
					return true;
			},
			// 上传之后回调
			onComplate: function(data) {
					$("#image").val(data);
					$("#img_preview").attr("src",data);
			}
		});
	}
	$(function(){
				$.post("/addmin/add",function(res,data,callback ){
					derburg;
				})
			})
</script>